package com.example.service;

import com.example.entity.User;
import com.example.mapper.UserMapper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.HashMap;

/**
 * @author 叶凯乐
 */
@Service
public class UserServiceImpl implements UserService {

    @Resource
    UserMapper userMapper;

    @Override
    public ArrayList<HashMap<String, String>> recieveMessage(String adminId, String userId) {
        return userMapper.selectContentAndPushTime(adminId, userId);
    }

    @Override
    public String doLogin(String userId, String password) {
        return userMapper.selectUsername(userId,password);
    }

    @Override
    public int changePassword(String userId, String oldPassword, String newPassword) {
        return userMapper.updatePassword(oldPassword, newPassword,userId);
    }

    @Override
    public ArrayList<String> listClassUsers(String userId) {
        String className=userMapper.selectClassName(userId);
        return userMapper.selectUsernames(className);
    }

    @Override
    public String getAdminName(String userId) {
        String adminId=userMapper.selectAdminId(userId);
        return userMapper.selectAdminUsername(adminId);
    }

    @Override
    public ArrayList<User> watchAll(String userId) {
    return userMapper.selectAllByUserId(userId);
    }
}
